package com.zr.task.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.zh.baselibrary.constant.BaseConstant;
import com.zh.baselibrary.utils.LogUtils;
import com.zh.baselibrary.utils.ShareManager;
import com.zh.baselibrary.views.ToastView;
import com.zr.task.utils.FilesUtils;

import java.io.File;
import java.io.IOException;

public class ShutDownReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        ToastView.showLong("重启");
        String time = ShareManager.getValue(context, BaseConstant.REBOOT_TIME);
        long longTime;
        if (TextUtils.isEmpty(time))
            longTime = 0L;
        else
            longTime = Long.parseLong(time);
        long nowTime =  System.currentTimeMillis();
        if ((nowTime - longTime) > 120000) {

            ShareManager.setValue(context,BaseConstant.REBOOT_TIME,String.valueOf(nowTime));
            String[] rebootArray = {"su", "-c", "reboot"};//执行重启的命令
            try {
                Runtime.getRuntime().exec(rebootArray);
            } catch (IOException io) {
            }
        }
    }
}
